module.exports = function($scope, $modal, $state, $timeout, $resource, $stateParams, str2date, date2str){

	var type = $stateParams.type;
	var sys_area = $stateParams.sys_area;

	$scope.myKeyup = function() {
		console.log('aaaaaa');
	}


	var url = '/api/as/tc/sale/wdfysaleNameBySubsidyList';

	// if(type == 'juyou'){
	// 	url = '/api/as/tc/sale/wdfysaleNameBySubsidyList';
	// }else if(type == 'shangke'){
	// 	url = '/api/as/tc/sale/wdsksaleNameBySubsidyList';
	// }

	// $resource('/api/as/wc/producttype/producttypelist', {}, {}).save({}, function (res) {
	// 	console.log(res);
 //        if(res.errcode === 0)
 //        {
 //        	$scope.typearr = res.data;
 //        	$scope.typearr.unshift({ type_name : '未设置类别', type_code: '0' });
 //        }
 //        else
 //        {
 //            alert(res.errmsg);
 //        }
	// });

	// $scope.setType = function(obj){

	// 	var para = {'id' : obj.id, 'type_code' : obj.type_code}

	// 	updateProduct(para);
	// };



	$scope.searchform = {};
	/* 分页
     * ========================================= */
	$scope.maxSize = 5;            //最多显示多少个按钮
	$scope.bigCurrentPage = 1;      //当前页码
	$scope.itemsPerPage = 10;         //每页显示几条

	$scope.load = function () {

		var para = {
			'pageNo': $scope.bigCurrentPage,
			'pageSize': $scope.itemsPerPage,
			'sale_category' : type,
			'sys_area' : sys_area,
		};

		//console.log($scope.searchform);

		para = angular.extend($scope.searchform, para);

		console.log(para);

		$resource(url, {}, {}).save(para, function (res) {
			console.log(para);
			console.log(res);

			if (res.errcode !== 0) {
				alert("数据获取失败");
				return;
			}

			$scope.objs = res.data.results;
			$scope.bigTotalItems = res.data.totalRecord;

		});

	};
	$scope.load();



	$scope.up = function(obj){

		var para = {
			'id' : obj.id,
			'sale_code' : obj.sale_code
		}

		$resource('/api/ac/wc/productService/createWarehouseProduct', {}, {}).save(para, function (res) {
			console.log(res);

			if (res.errcode !== 0) {
				alert("数据获取失败");
				return;
			}

			alert('上架成功');

		});

	}


};
